import 'package:dio/dio.dart';
import 'package:e_book/utils/log_utils.dart';

class PrintLogInterceptor extends InterceptorsWrapper{
  // 请求打印
  @override
  void onRequest(RequestOptions options, RequestInterceptorHandler handler) {
    //打印请求信息，方便调试
    LogUtils.printIn("\nonRequest---------->");
    options.headers.forEach((key,value){
      LogUtils.printIn("headers:key=$key value=${value.toString()}");
    });
    LogUtils.printIn("path:${options.uri}");
    LogUtils.printIn("method:${options.method}");
    LogUtils.printIn("data:${options.data}");
    LogUtils.printIn("queryParameters:${options.queryParameters.toString()}");
    LogUtils.printIn("<----------onRequest\n");
    super.onRequest(options,handler);
  }

  // 响应打印
  // @override
  // void onResponse(Response response,ResponseInterceptorHandler handler){
  //   LogUtils.printIn("InonResponse--------->");
  //   LogUtils.printIn("path:${response.realUri}");
  //   LogUtils.printIn("headers:${response.headers.toString()}");
  //   LogUtils.printIn("statusMessage:${response.statusMessage}");
  //   LogUtils.printIn("statusCode:${response.statusCode}");
  //   LogUtils.printIn("eltra:${response.extra.toString()}");
  //   LogUtils.printIn("data:${response.data}");
  //   LogUtils.printIn("<----------onResponseln");
  //   super.onResponse(response,handler);
  // }

  // 错误打印
  @override
  void onError(DioException err,ErrorInterceptorHandler handler){
    LogUtils.printIn("\nonError---------->");
    LogUtils.printIn("error:${err.toString()}");
    LogUtils.printIn("<----------onError\n");
    super.onError(err,handler);
  }
}